package com.example.online.music.controller;

import com.example.online.music.common.R;
import com.example.online.music.model.request.SingerRequest;
import com.example.online.music.service.SingerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class SingerController {

    @Autowired
    private SingerService singerService;


    // 添加歌手
    @PostMapping("/singer/add")
    public R addSinger(@RequestBody SingerRequest addSingerRequest) {
        return singerService.addSinger(addSingerRequest);
    }

    // 删除歌手
    @DeleteMapping("/singer/delete")
    public R deleteSinger(@RequestParam int id) {
        return singerService.deleteSinger(id);
    }

    // 返回所有歌手
//    @GetMapping("/singer")
    @Deprecated //弃用
    public R allSinger() {
        return singerService.allSinger();
    }

    /**
     * @Description: 用户端歌手列表查询
     * @Author: yang_yong
     * @CreateTime:
     * @param: sex 性别：0-女歌手，1-男歌手，2-组合歌手，-1 所有歌手
     * @return: com.example.online.music.common.R
     **/
    @GetMapping("/singer")
    public R singerList(@RequestParam(defaultValue = "-1") int sex) {
        return singerService.singerList(sex);
    }

    // 根据歌手名查找歌手
    @GetMapping("/singer/name/detail")
    public R singerOfName(@RequestParam String name) {
        return singerService.singerOfName(name);
    }

    // 根据歌手性别查找歌手
    @GetMapping("/singer/sex/detail")
    public R singerOfSex(@RequestParam int sex) {
        return singerService.singerOfSex(sex);
    }

    // 更新歌手信息
    @PostMapping("/singer/update")
    public R updateSingerMsg(@RequestBody SingerRequest updateSingerRequest) {
        return singerService.updateSingerMsg(updateSingerRequest);
    }

    // 更新歌手头像
    @PostMapping("/singer/avatar/update")
    public R updateSingerPic(@RequestParam("file") MultipartFile avatorFile, @RequestParam("id") int id) {
        return singerService.updateSingerPic(avatorFile, id);
    }
}
